/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package petstore.view.action;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author Tom Hayden
 */
public class CustomDispatchAction extends DispatchAction {

    // FORWARDS
    public static final String HOME = "home";
    public static final String SUCCESS = "success";
    public static final String ERROR = "error";
    public static final String OUPUT_WRITER = "/outputWriter";
    
    // ACTIONS
    public static final String DEFAULT_RETURN_PATH = "home.do";
    
    // BEANS
    public static final String BEAN = "bean";
    public static final String USER = "user";
    public static final String COLLECTION = "collection";
    public static final String RETURN_PATH = "returnPath";

    public void setBeanInSession(HttpServletRequest request, Object bean) {
        request.getSession().setAttribute(BEAN, bean);
    }

    public Object getBeanInSession(HttpServletRequest request) {
        return request.getSession().getAttribute(BEAN);
    }

    public void removeBeanOfSession(HttpServletRequest request) {
        request.getSession().removeAttribute(BEAN);
    }

    public void setCollectionInSession(HttpServletRequest request, Object collection) {
        request.getSession().setAttribute(COLLECTION, collection);
    }

    public Object getCollectionInSession(HttpServletRequest request) {
        return request.getSession().getAttribute(COLLECTION);
    }

    public void removeCollectionOfSession(HttpServletRequest request) {
        request.getSession().removeAttribute(COLLECTION);
    }

    public void setUserInSession(HttpServletRequest request, Object user) {
        request.getSession().setAttribute(USER, user);
    }

    public Object getUserInSession(HttpServletRequest request) {
        return request.getSession().getAttribute(USER);
    }

    public void removeUserOfSession(HttpServletRequest request) {
        request.getSession().removeAttribute(USER);
    }
    
    public void setDefaultReturnPath(HttpServletRequest request) {
        request.setAttribute(RETURN_PATH, DEFAULT_RETURN_PATH);
    }
    
    public void setReturnPath(HttpServletRequest request, String returnPath) {
        request.setAttribute(RETURN_PATH, returnPath);
    }

}
